package com.hotkid.ceo.jetpack.myjetpackmvvm.data.http.interceptor

import com.hotkid.ceo.jetpack.myjetpackmvvm.common.MyConfig
import com.yechaoa.yutilskt.SpUtil
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException
import kotlin.jvm.Throws

/**
 * ClassName:AddCookiesInterceptor
 * Package:com.hotkid.ceo.jetpack.myjetpackmvvm.data.http.interceptor
 * Description:从响应头里拿到cookies存起来，后续继续使用
 * @date:2021/3/19 4:31 PM
 * @author:774169396@qq.com
 */
class AddCookiesInterceptor :Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val builder=chain.request().newBuilder()
        val stringSet=SpUtil.getStringSet(MyConfig.COOKIE)
        for (cookie in stringSet) {
            builder.addHeader("Cookie", cookie)
        }
        return chain.proceed(builder.build())

    }
}